package cn.uestc.labhms.modules.hms.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.ToString;

import java.io.Serializable;
import java.util.List;

/**
 * 分页工具类
 *
 * @author Mu.tz
 */
@ToString
public class HMSPageUtils implements Serializable {
	private static final long serialVersionUID = 1L;
	private String tableName;
	/**
	 * 总记录数
	 */
	private int totalCount;
	/**
	 * 每页记录数
	 */
	private int pageSize;
	/**
	 * 总页数
	 */
	private int totalPage;
	/**
	 * 当前页数
	 */
	private int currentPage;
	/**
	 * 列表数据
	 */
	private List<?> tableCell;
	
	/**
	 * 分页
	 * @param tableCell        列表数据
	 * @param totalCount  总记录数
	 * @param pageSize    每页记录数
	 * @param currPage    当前页数
	 */
	public HMSPageUtils(List<?> tableCell, int totalCount, int pageSize, int currPage, String tableName) {
		this.tableCell = tableCell;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.currentPage = currPage;
		this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
		this.tableName = tableName;
	}

	/**
	 * 分页
	 */
	public HMSPageUtils(IPage<?> page) {
		this.tableCell = page.getRecords();
		this.totalCount = (int)page.getTotal();
		this.pageSize = (int)page.getSize();
		this.currentPage = (int)page.getCurrent();
		this.totalPage = (int)page.getPages();
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrPage() {
		return currentPage;
	}

	public void setCurrPage(int currPage) {
		this.currentPage = currPage;
	}

	public List<?> getTableCell() {
		return tableCell;
	}

	public void setTableCell(List<?> tableCell) {
		this.tableCell = tableCell;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
}
